package com.yvon.gprc.server.service;

import com.yvon.grpc.api.HelloRequest;
import com.yvon.grpc.api.HelloResponse;
import com.yvon.grpc.api.HelloWorldGrpc;
import io.grpc.stub.StreamObserver;
import net.devh.boot.grpc.server.service.GrpcService;
import org.springframework.beans.factory.annotation.Value;

/**
 * @author : wangyufeng
 * @since : 2021-10-18
 */
@GrpcService
public class HelloWorldService extends HelloWorldGrpc.HelloWorldImplBase {

    @Value("${server.port")
    private String port;

    @Override
    public void hello(HelloRequest request, StreamObserver<HelloResponse> responseObserver) {
        String message = String.format("Welcome to WenDev, your message is %s, from port %s."
                        + "From: Spring Cloud + gRPC.",
                request.getMessage(), port);
        HelloResponse response = HelloResponse.newBuilder().setResponse(message).build();
        responseObserver.onNext(response);
        responseObserver.onCompleted();
    }
}
